<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-form-item label="方案编码" prop="strategyCode">
        <el-input
          v-model="queryParams.strategyCode"
          placeholder="请输入方案编码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="方案名称" prop="strategyName">
        <el-input
          v-model="queryParams.strategyName"
          placeholder="请输入方案名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
        <el-button
          :icon="!isOpen ? 'el-icon-arrow-down' : 'el-icon-arrow-up'"
          size="mini"
          @click="shouqi"
          >展开/收起</el-button
        >
      </el-form-item>

      <div v-if="isOpen">
        <el-form-item label="优先级" prop="priorityLevel">
          <el-input
            v-model="queryParams.priorityLevel"
            placeholder="请输入优先级"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="配货来源" prop="allocationSource">
          <el-input
            v-model="queryParams.allocationSource"
            placeholder="请输入配货来源"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="品牌" prop="brand">
          <el-input
            v-model="queryParams.brand"
            placeholder="请输入品牌"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="生效开始日期" prop="effectiveStartDate">
          <el-date-picker
            clearable
            v-model="queryParams.effectiveStartDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择生效开始日期"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="生效结束日期" prop="effectiveEndDate">
          <el-date-picker
            clearable
            v-model="queryParams.effectiveEndDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择生效结束日期"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="配货方式" prop="allocationMethod">
          <el-input
            v-model="queryParams.allocationMethod"
            placeholder="请输入配货方式"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="订单号" prop="orderId">
          <el-input
            v-model="queryParams.orderId"
            placeholder="请输入订单号"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="商品编码" prop="productCode">
          <el-input
            v-model="queryParams.productCode"
            placeholder="请输入商品编码"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="最近N天" prop="recentDaysCount">
          <el-input
            v-model="queryParams.recentDaysCount"
            placeholder="请输入最近N天"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="分货开始日期" prop="startAllocationDate">
          <el-date-picker
            clearable
            v-model="queryParams.startAllocationDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择分货开始日期"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="分货结束日期" prop="endAllocationDate">
          <el-date-picker
            clearable
            v-model="queryParams.endAllocationDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择分货结束日期"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="分配优先级模式" prop="priorityAllocationMode">
          <el-input
            v-model="queryParams.priorityAllocationMode"
            placeholder="请输入分配优先级模式"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="触发比例" prop="triggerRatio">
          <el-input
            v-model="queryParams.triggerRatio"
            placeholder="请输入触发比例"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="触发颗粒度" prop="triggerGranularity">
          <el-input
            v-model="queryParams.triggerGranularity"
            placeholder="请输入触发颗粒度"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="完结是否分配" prop="isCompletedAssigned">
          <el-input
            v-model="queryParams.isCompletedAssigned"
            placeholder="请输入完结是否分配"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="商品留仓比例" prop="productStockRatio">
          <el-input
            v-model="queryParams.productStockRatio"
            placeholder="请输入商品留仓比例"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="分配颗粒度" prop="allocationGranularity">
          <el-input
            v-model="queryParams.allocationGranularity"
            placeholder="请输入分配颗粒度"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="完结是否留仓" prop="isCompletedRemained">
          <el-input
            v-model="queryParams.isCompletedRemained"
            placeholder="请输入完结是否留仓"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="分货比例模式" prop="orderDistributionRatio">
          <el-input
            v-model="queryParams.orderDistributionRatio"
            placeholder="请输入分货比例模式"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item
          label="分货比例开始日期"
          prop="distributionRatioStartDate"
        >
          <el-date-picker
            clearable
            v-model="queryParams.distributionRatioStartDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择分货比例开始日期"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="分货比例结束日期" prop="distributionRatioEndDate">
          <el-date-picker
            clearable
            v-model="queryParams.distributionRatioEndDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择分货比例结束日期"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="是否自动审核" prop="autoApprove">
          <el-input
            v-model="queryParams.autoApprove"
            placeholder="请输入是否自动审核"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="是否通知" prop="isNotified">
          <el-input
            v-model="queryParams.isNotified"
            placeholder="请输入是否通知"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
      </div>
      <!-- <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item> -->
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['productAllocation:strategy:add']"
          >新增</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['productAllocation:strategy:edit']"
          >修改</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['productAllocation:strategy:remove']"
          >删除</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['productAllocation:strategy:export']"
          >导出</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button v-show="showBtn" size="mini" @click="handleStrategy">
          选择方案编码
        </el-button>
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table
      v-loading="loading"
      :data="strategyList"
      @selection-change="handleSelectionChange"
      :height="600"
    >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="id" align="center" prop="id" />
      <el-table-column label="方案编码" align="center" prop="strategyCode" />
      <el-table-column label="方案名称" align="center" prop="strategyName" />
      <el-table-column
        width="150"
        label="方案信息操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleCreated(scope.row)"
            >配置</el-button
          >
        </template>
      </el-table-column>
      <el-table-column label="优先级" align="center" prop="priorityLevel" />
      <el-table-column label="配货方式" align="center" prop="allocationMethod">
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.sys_product_allocation_method"
            :value="scope.row.allocationMethod"
          />
        </template>
      </el-table-column>
      <!-- <el-table-column
        label="配货来源"
        align="center"
        prop="allocationSource"
      />
      <el-table-column label="品牌" align="center" prop="brand" /> -->
      <el-table-column
        label="生效开始日期"
        align="center"
        prop="effectiveStartDate"
        width="180"
      >
        <template slot-scope="scope">
          <span>{{
            parseTime(scope.row.effectiveStartDate, "{y}-{m}-{d}")
          }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="生效结束日期"
        align="center"
        prop="effectiveEndDate"
        width="180"
      >
        <template slot-scope="scope">
          <span>{{
            parseTime(scope.row.effectiveEndDate, "{y}-{m}-{d}")
          }}</span>
        </template>
      </el-table-column>
      <!-- <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column
        label="配货方式"
        align="center"
        prop="allocationMethod"
      />
      <el-table-column label="订单号" align="center" prop="orderId" />
      <el-table-column label="商品编码" align="center" prop="productCode" />
      <el-table-column label="最近N天" align="center" prop="recentDaysCount" />
      <el-table-column
        label="分货开始日期"
        align="center"
        prop="startAllocationDate"
        width="180"
      >
        <template slot-scope="scope">
          <span>{{
            parseTime(scope.row.startAllocationDate, "{y}-{m}-{d}")
          }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="分货结束日期"
        align="center"
        prop="endAllocationDate"
        width="180"
      >
        <template slot-scope="scope">
          <span>{{
            parseTime(scope.row.endAllocationDate, "{y}-{m}-{d}")
          }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="分配优先级模式"
        align="center"
        prop="priorityAllocationMode"
      />
      <el-table-column label="触发比例" align="center" prop="triggerRatio" />
      <el-table-column
        label="触发颗粒度"
        align="center"
        prop="triggerGranularity"
      />
      <el-table-column
        label="完结是否分配"
        align="center"
        prop="isCompletedAssigned"
      />
      <el-table-column
        label="商品留仓比例"
        align="center"
        prop="productStockRatio"
      />
      <el-table-column
        label="分配颗粒度"
        align="center"
        prop="allocationGranularity"
      />
      <el-table-column
        label="完结是否留仓"
        align="center"
        prop="isCompletedRemained"
      />
      <el-table-column
        label="分货比例模式"
        align="center"
        prop="orderDistributionRatio"
      />
      <el-table-column
        label="分货比例开始日期"
        align="center"
        prop="distributionRatioStartDate"
        width="180"
      >
        <template slot-scope="scope">
          <span>{{
            parseTime(scope.row.distributionRatioStartDate, "{y}-{m}-{d}")
          }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="分货比例结束日期"
        align="center"
        prop="distributionRatioEndDate"
        width="180"
      >
        <template slot-scope="scope">
          <span>{{
            parseTime(scope.row.distributionRatioEndDate, "{y}-{m}-{d}")
          }}</span>
        </template>
      </el-table-column>
      <el-table-column label="是否自动审核" align="center" prop="autoApprove" />
      <el-table-column label="是否通知" align="center" prop="isNotified" /> -->
      <el-table-column label="状态" align="center">
        <template slot-scope="scope">
          <el-switch
            v-model="scope.row.status"
            active-value="0"
            inactive-value="1"
            @change="handleStatusChange(scope.row)"
          ></el-switch>
        </template>
      </el-table-column>
      <el-table-column label="创建人" align="center" prop="creator" />
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['productAllocation:strategy:edit']"
            >修改</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['productAllocation:strategy:remove']"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改采购分货策略对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <!-- <el-form-item label="方案编码" prop="strategyCode">
          <el-input v-model="form.strategyCode" placeholder="请输入方案编码" />
        </el-form-item> -->
        <el-form-item label="方案名称" prop="strategyName">
          <el-input v-model="form.strategyName" placeholder="请输入方案名称" />
          <!-- <el-select
            v-model="form.strategyName"
            placeholder="方案名称"
            clearable
            style="width: 240px"
          >
            <el-option
              v-for="dict in strategyNameList"
              :key="dict"
              :label="dict"
              :value="dict"
            />
          </el-select> -->
        </el-form-item>
        <!-- <el-form-item label="优先级" prop="priorityLevel">
          <el-input v-model="form.priorityLevel" placeholder="请输入优先级" />
        </el-form-item>
        <el-form-item label="配货来源" prop="allocationSource">
          <el-input
            v-model="form.allocationSource"
            placeholder="请输入配货来源"
          />
        </el-form-item>
        <el-form-item label="品牌" prop="brand">
          <el-input v-model="form.brand" placeholder="请输入品牌" />
        </el-form-item>
        <el-form-item label="生效开始日期" prop="effectiveStartDate">
          <el-date-picker
            clearable
            v-model="form.effectiveStartDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择生效开始日期"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="生效结束日期" prop="effectiveEndDate">
          <el-date-picker
            clearable
            v-model="form.effectiveEndDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择生效结束日期"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" placeholder="请输入备注" />
        </el-form-item>
        <el-form-item label="配货方式" prop="allocationMethod">
          <el-input
            v-model="form.allocationMethod"
            placeholder="请输入配货方式"
          />
        </el-form-item>
        <el-form-item label="订单号" prop="orderId">
          <el-input v-model="form.orderId" placeholder="请输入订单号" />
        </el-form-item>
        <el-form-item label="商品编码" prop="productCode">
          <el-input v-model="form.productCode" placeholder="请输入商品编码" />
        </el-form-item>
        <el-form-item label="最近N天" prop="recentDaysCount">
          <el-input
            v-model="form.recentDaysCount"
            placeholder="请输入最近N天"
          />
        </el-form-item>
        <el-form-item label="分货开始日期" prop="startAllocationDate">
          <el-date-picker
            clearable
            v-model="form.startAllocationDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择分货开始日期"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="分货结束日期" prop="endAllocationDate">
          <el-date-picker
            clearable
            v-model="form.endAllocationDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择分货结束日期"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="分配优先级模式" prop="priorityAllocationMode">
          <el-input
            v-model="form.priorityAllocationMode"
            placeholder="请输入分配优先级模式"
          />
        </el-form-item>
        <el-form-item label="触发比例" prop="triggerRatio">
          <el-input v-model="form.triggerRatio" placeholder="请输入触发比例" />
        </el-form-item>
        <el-form-item label="触发颗粒度" prop="triggerGranularity">
          <el-input
            v-model="form.triggerGranularity"
            placeholder="请输入触发颗粒度"
          />
        </el-form-item>
        <el-form-item label="完结是否分配" prop="isCompletedAssigned">
          <el-input
            v-model="form.isCompletedAssigned"
            placeholder="请输入完结是否分配"
          />
        </el-form-item>
        <el-form-item label="商品留仓比例" prop="productStockRatio">
          <el-input
            v-model="form.productStockRatio"
            placeholder="请输入商品留仓比例"
          />
        </el-form-item>
        <el-form-item label="分配颗粒度" prop="allocationGranularity">
          <el-input
            v-model="form.allocationGranularity"
            placeholder="请输入分配颗粒度"
          />
        </el-form-item>
        <el-form-item label="完结是否留仓" prop="isCompletedRemained">
          <el-input
            v-model="form.isCompletedRemained"
            placeholder="请输入完结是否留仓"
          />
        </el-form-item>
        <el-form-item label="分货比例模式" prop="orderDistributionRatio">
          <el-input
            v-model="form.orderDistributionRatio"
            placeholder="请输入分货比例模式"
          />
        </el-form-item>
        <el-form-item
          label="分货比例开始日期"
          prop="distributionRatioStartDate"
        >
          <el-date-picker
            clearable
            v-model="form.distributionRatioStartDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择分货比例开始日期"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="分货比例结束日期" prop="distributionRatioEndDate">
          <el-date-picker
            clearable
            v-model="form.distributionRatioEndDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择分货比例结束日期"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="是否自动审核" prop="autoApprove">
          <el-input
            v-model="form.autoApprove"
            placeholder="请输入是否自动审核"
          />
        </el-form-item>
        <el-form-item label="是否通知" prop="isNotified">
          <el-input v-model="form.isNotified" placeholder="请输入是否通知" />
        </el-form-item> -->
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <el-dialog
      :visible.sync="openInfo"
      width="1600px"
      append-to-body
      v-if="openInfo"
    >
      <stepsStrategy :rowitem="row" />
    </el-dialog>
  </div>
</template>

<script>
import {
  listStrategy,
  getStrategy,
  delStrategy,
  addStrategy,
  updateStrategy,
} from "@/api/productAllocation/strategy";
import stepsStrategy from "@/views/productAllocation/stepsStrategy/index.vue";
export default {
  name: "Strategy",
  dicts: [
    "sys_product_allocationtype",
    "sys_product_pp",
    "sys_product_allocationsource",
    "sys_product_allocation_method",
  ],
  components: { stepsStrategy },
  props: {
    strategyCode: {
      type: String,
      default: null,
    },
    showBtn: {
      type: Boolean,
      default: false,
    },
  },
  data() {
    return {
      // showBtn: false,
      row: {},
      openInfo: false,
      list: [],
      strategyNameList: ["全渠道分货", "返修品分货", "其他入仓分货"],
      isOpen: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 采购分货策略表格数据
      strategyList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        strategyCode: null,
        strategyName: null,
        priorityLevel: null,
        allocationType: null,
        allocationSource: null,
        brand: null,
        effectiveStartDate: null,
        effectiveEndDate: null,
        allocationMethod: null,
        orderId: null,
        productCode: null,
        recentDaysCount: null,
        startAllocationDate: null,
        endAllocationDate: null,
        priorityAllocationMode: null,
        triggerRatio: null,
        triggerGranularity: null,
        isCompletedAssigned: null,
        productStockRatio: null,
        allocationGranularity: null,
        isCompletedRemained: null,
        orderDistributionRatio: null,
        distributionRatioStartDate: null,
        distributionRatioEndDate: null,
        autoApprove: null,
        isNotified: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
    };
  },
  created() {
    this.getList();
  },
  watch: {
    showBtn: {
      handler: function (newnew, oldold) {},
      deep: true,
      immediate: true,
    },
    strategyCode: {
      handler: function (newnew, oldold) {
        this.queryParams.strategyCode = this.strategyCode;

        this.getList();
      },
      deep: true,
      immediate: true,
    },
  },
  methods: {
    handleStrategy() {
      if (this.list.length != 1) {
        this.$modal.msgError("只选一个方案编码");
        return;
      }
      this.$emit("handleStrategy", this.list[0].strategyCode);
    },
    // 用户状态修改
    handleStatusChange(row) {
      let text = row.status === "0" ? "启用" : "停用";
      this.$modal
        .confirm('确认要"' + text + '"吗？')
        .then(function () {
          return updateStrategy({
            id: row.id,
            status: row.status,
          });
        })
        .then(() => {
          this.$modal.msgSuccess(text + "成功");
        })
        .catch(function () {
          row.status = row.status === "0" ? "1" : "0";
        });
    },
    handleCreated(row) {
      // this.$router.push({
      //   path: "/productAllocation/futures/stepsStrategy",
      //   query: { obj: row },
      // });
      this.row = row;
      this.openInfo = true;
    },
    //搜索栏展示与收起
    shouqi() {
      // console.log(1);
      this.isOpen = !this.isOpen;
    },
    /** 查询采购分货策略列表 */
    getList() {
      this.loading = true;
      listStrategy(this.queryParams).then((response) => {
        this.strategyList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        strategyCode: null,
        strategyName: null,
        priorityLevel: null,
        allocationType: null,
        allocationSource: null,
        brand: null,
        effectiveStartDate: null,
        effectiveEndDate: null,
        remark: null,
        allocationMethod: null,
        orderId: null,
        productCode: null,
        recentDaysCount: null,
        startAllocationDate: null,
        endAllocationDate: null,
        priorityAllocationMode: null,
        triggerRatio: null,
        triggerGranularity: null,
        isCompletedAssigned: null,
        productStockRatio: null,
        allocationGranularity: null,
        isCompletedRemained: null,
        orderDistributionRatio: null,
        distributionRatioStartDate: null,
        distributionRatioEndDate: null,
        autoApprove: null,
        isNotified: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.list = selection.map((item) => item);
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加采购分货策略";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids;
      getStrategy(id).then((response) => {
        this.form = response.data;
        this.open = true;
        this.title = "修改采购分货策略";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.id != null) {
            updateStrategy(this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addStrategy(this.form).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal
        .confirm('是否确认删除采购分货策略编号为"' + ids + '"的数据项？')
        .then(function () {
          return delStrategy(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "productAllocation/strategy/export",
        {
          ...this.queryParams,
        },
        `strategy_${new Date().getTime()}.xlsx`
      );
    },
  },
};
</script>
